//
//  ETHJsonRpcKit.h
//  CryptoGirl
//
//  Created by yiren on 2018/6/11.
//  Copyright © 2018年 邓昊. All rights reserved.
//

#import <Foundation/Foundation.h>
@class  AFHTTPSessionManager;
@class Account;
//账户信息出口//
typedef void(^AccountInfoBlock)(NSDictionary *dic);
typedef void(^ResponseBlock)(BOOL success);
typedef void(^BalanceBlock)(NSString *balance);
typedef void(^SignedBlock)(NSString *result);

@interface ETHJsonRpcKit : NSObject

@property (nonatomic, strong) Account               *account;
@property (nonatomic, strong) NSString              *gas;
@property (nonatomic, strong) NSString              *gasprice;
@property (nonatomic, strong) AFHTTPSessionManager  *sessionManager;
@property (nonatomic, strong) NSString              *endPoint;
@property (nonatomic, strong) NSMutableDictionary   *userDic;
@property (nonatomic, copy)   AccountInfoBlock       accountInfoBlock;
@property (nonatomic, copy)   ResponseBlock          responseBlock;
@property (nonatomic, copy)   BalanceBlock           balanceBlock;
@property (nonatomic, copy)   SignedBlock            signedBlock;

+ (instancetype)sharedInstance;
//data str 转换//
+ (NSString *)convertDataToHexStr:(NSData *)data;
+ (NSData *)convertHexStrToData:(NSString *)str;
+ (NSString *)sha3:(NSString *)str; //8bit sha3
+ (NSString *)fullSha3:(NSString *)str; //full sha3
- (NSString *)calculateParameterWithType:(NSInteger *)type andValue:(NSString *)value;//0-uint 1-address 2-bool 3-uint256 4-byte 5-array

//Wallet API////
- (void)getAccountWithDic: (NSDictionary *)dic;
- (void)creatAccountWithPassword:(NSString *)password accountName:(NSString *)name;
- (void)importAccountWithPassword:(NSString *)password accountName:(NSString *)name key:(NSString *)keyphrase andType:(NSInteger)type;
//- (void)ethSign:(NSString *)str;
- (void)ethSignData:(NSData *)data; //签名data
//获取余额
- (void)getBalanceForAccount:(NSString *)address;
//账户列表专用
- (void)getBalanceForAccountList:(NSString *)address;

//jsonRPC
- (void)ethCall:(NSString *)toAddress andContract: (NSString *)conData response:(void (^)(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error))response;      //eth_call
- (void)sendRawTransaction: (NSData *)data;    //send_rawTransaction
- (void)sendTransaction:(NSDictionary *)dic;//sendTransaction
- (void)getReceipt:(NSString *)response;

//afnetworking 调用其他RPC方法用
- (void)invokeMethod:(NSString *)method
      withParameters:(id)parameters
            response:(void (^)(NSURLResponse * _Nonnull response, id  _Nullable responseObject, NSError * _Nullable error))response;
@end
